package com.zhu.commentstatisticspublisher.config;


import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;

/**
 * Mysql数据源
 */

public class FirstDataSource {


    @Value("${spring.datasource.one.url}")
    private String url;


    @Value("${spring.datasource.one.username}")
    private String username;

    @Value("${spring.datasource.one.password}")
    private String password;

    @Value("${spring.datasource.one.driver-class-name}")
    private String driverClassName;


    /**
     * 配置数据源
     */

    @Bean(name="setDataSource")
    @Primary
    public DataSource setDataSource(){



        DriverManagerDataSource dataSource=new DriverManagerDataSource();
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setDriverClassName(driverClassName);
        return  dataSource;
    }


    /**
     * 配置jdbcTemplate
     */

    @Bean(name = "firstJdbcTemplate")
    public JdbcTemplate getJdbcTemplate(@Qualifier("setDataSource")DataSource dataSource){
        return new JdbcTemplate(dataSource);
    }


}

